package com.tyqx.hashchainbiz.service.impl;

import com.tyqx.hashchainbean.module.JZTLogistics;
import com.tyqx.hashchainbean.module.JZTLogisticsRelationship;
import com.tyqx.hashchainbiz.service.JZTLogisticsRelationshipService;
import com.tyqx.hashchainbiz.service.JZTLogisticsService;
import com.tyqx.hashchaindao.mapper.JZTLogisticsMapper;
import com.tyqx.hashchaindao.mapper.JZTLogisticsRelationshipMapper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Transactional(rollbackFor = Exception.class)
@Service("jztLogisticsRelationshipService")
public class JZTLogisticsRelationshipServiceImpl implements JZTLogisticsRelationshipService {

    @Resource
    private JZTLogisticsRelationshipMapper jztLogisticsRelationshipMapper;


    @Override
    public Integer addJZTLogisticsRelationship(JZTLogisticsRelationship jztLogisticsRelationship)  {
        try {
           /* Date currentDate = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date createTime = sdf.parse(sdf.format(currentDate));
            jztLogisticsRelationship.setCreateTime(createTime);
            jztLogisticsRelationship.setUpdateTime(createTime);*/
            return jztLogisticsRelationshipMapper.addJZTLogisticsRelationship(jztLogisticsRelationship);
        }catch(RuntimeException e){
            e.printStackTrace();
            throw new RuntimeException();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public List<String> getParentTraceabilityCodeByTraceabilityCode(String traceabilityCode) {
        return jztLogisticsRelationshipMapper.getParentTraceabilityCodeByTraceabilityCode(traceabilityCode);
    }

    @Override
    public Integer insertBatch(List<JZTLogisticsRelationship> jztLogisticsRelationshipList) {
        return jztLogisticsRelationshipMapper.insertBatch(jztLogisticsRelationshipList);
    }
}
